package com.dhcc.sdc.busi.controller;


import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;


import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.annotion.BussinessLog;

import com.dhcc.sdc.busi.entity.SdcBusiEvaluationItemEntity;
import com.dhcc.sdc.busi.service.ISdcBusiEvaluationItemService;


/**
 * 
 * 
 * @ClassName: SdcBusiEvaluationItemController
 * @Description: TODO
 * @author jumper
 * @date 2021-09-14 16:36:23
 */
@Controller
@RequestMapping("${sys.backendPath}/sdc/sdcbusievaluationitem")
public class SdcBusiEvaluationItemController extends BaseController {

	private String PREFIX = "/backend/sdc/sdcbusievaluationitem/";

	@Autowired
	private ISdcBusiEvaluationItemService sdcBusiEvaluationItemService;
	

    /**
     * 跳转到列表首页
     */
    @RequestMapping("")
    @Permission("sdcbusievaluationitem:list")
    public String index() {
        return PREFIX + "sdcbusievaluationitem.html";
    }
	
    /**
     * 跳转到新增
     */
    @RequestMapping("/to_add")
    @Permission("sdcbusievaluationitem:add")
    public String toAdd() {
        return PREFIX + "sdcbusievaluationitem_add.html";
    }
	
	/**
     * 跳转到修改
     */
    @RequestMapping("/to_update/{sdcBusiEvaluationItemId}")
    @Permission("sdcbusievaluationitem:update")
    public String toUpdate(@PathVariable Long sdcBusiEvaluationItemId, Model model) {
        SdcBusiEvaluationItemEntity sdcBusiEvaluationItem = this.sdcBusiEvaluationItemService.selectById(sdcBusiEvaluationItemId);
        model.addAttribute("sdcBusiEvaluationItem",sdcBusiEvaluationItem);
        return PREFIX + "sdcbusievaluationitem_edit.html";
    }

    /**
     * 获取列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("sdcbusievaluationitem:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdcBusiEvaluationItemEntity> page = new PageFactory<SdcBusiEvaluationItemEntity>().defaultPage();
        List<SdcBusiEvaluationItemEntity> result = this.sdcBusiEvaluationItemService.page(page,params);
        page.setRecords((List<SdcBusiEvaluationItemEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("sdcbusievaluationitem:add")
    @BussinessLog(value = "新增")
    public Object add(SdcBusiEvaluationItemEntity sdcBusiEvaluationItem) {
        if (CommonUtil.isOneEmpty(sdcBusiEvaluationItem)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdcBusiEvaluationItem.insert();
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("sdcbusievaluationitem:delete")
    @BussinessLog(value = "删除")
    public Object delete(@RequestParam Long sdcBusiEvaluationItemId) {
	
        this.sdcBusiEvaluationItemService.deleteById(sdcBusiEvaluationItemId);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("sdcbusievaluationitem:update")
    @BussinessLog(value = "修改")
    public Object update(SdcBusiEvaluationItemEntity sdcBusiEvaluationItem) {
        if (CommonUtil.isOneEmpty(sdcBusiEvaluationItem)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdcBusiEvaluationItemEntity old = this.sdcBusiEvaluationItemService.selectById(sdcBusiEvaluationItem.getId());

        old.setEvaluationId(sdcBusiEvaluationItem.getEvaluationId());
        old.setAssessmentEntryId(sdcBusiEvaluationItem.getAssessmentEntryId());
        old.setUptateTime(sdcBusiEvaluationItem.getUptateTime());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
